<include file="../header" />
<head>
	<link rel="stylesheet" href="/assets/schoolirs/css/countdown.css?version=1">
</head>
<body>
<div class="wraper">

    <div class="top">
        <p>
            <a href="{BEESCRM:$backUrl}" class="iconfont icon-zuo pull-left"></a>
            <a href="javascript:void(0);" class="order-all pull-left">确认订单</a>
        </p>
	    <input type="hidden" id="send_price" value="{BEESCRM:$sendPrice}">
	    <input type="hidden" id="close_time" value="{BEESCRM:$closeTime}">
	    <input type="hidden" id="orderId" value="{BEESCRM:$order_id}">
	    <input type="hidden" id="irsId" value="{BEESCRM:$irs_id}">
    </div>
	<div class="tips">
		温馨提示：付款后不能退单,请在<strong id="minute_show">0分</strong>
		<strong id="second_show">0秒</strong>内完成付款</br>
	</div>

    <div class="order-info topnone">
        <div class="lists">
            就餐地点
            <span class="pull-right">{BEESCRM:$window_name}({BEESCRM:$refectory_name})</span>
        </div>
    </div>
    <div class="order-info">
        <div class="lists tb-mode">
            <div class="tb-cell list-left">就餐时间</div>
            <div class="tb-cell list-right" style="width: 15%;">{BEESCRM:$eatTime}</div>
        </div>
    </div>
	<div class="order-info">
		<div class="lists tb-mode" id="paytype">
			<div class="tb-cell list-left">支付方式</div>
			<div class="tb-cell list-right">
				<a href="javascript:void(0);" class="paymethod" >{BEESCRM:$pay_method}<span class="iconfont icon-you"></span></a>
			</div>
		</div>
	</div>
    <if condition="$hasBalconyRight eq 0">
        <div class="order-info">
            <div class="lists tb-mode">
                <div class="tb-cell list-left">桌号</div>
                <div class="tb-cell list-right">
                   <a href="javascript:void(0);" class="disbalcony" data-type="1">无可预订包厢
                       <span class="iconfont icon-you text-gray"></span>
                   </a>
                </div>
            </div>
        </div>
    </if>
    <if condition="$hasBalconyRight eq 1">
		<div class="order-info" id="balcony_div">
			<div class="lists tb-mode">
				<div class="tb-cell list-left">桌号</div>
				<div class="tb-cell list-right">
					<empty name="hasBalcony">
						<a href="javascript:void(0);" class="disbalcony" data-type="1">无可预订包厢</a>
					<else/>
						<a href="javascript:void(0)" class="abledbalcony" data-type="1">
							<if condition="($hasOrderBalcony eq 1) AND ($hasBalcony eq 1)">
								{BEESCRM:$balconyInfo.balcony_name}

							</if>
							<if condition="($hasOrderBalcony eq 0) AND ($hasBalcony eq 1)">
								不预定

							</if>
							<span class="iconfont icon-you text-gray"></span>
						</a>
					</empty>
				</div>
			</div>
		</div>
	</if>
	<if condition="$is_take eq 1">
		<div class="order-info">
			<div class="lists">
				<div class="tb-mode">
					<div class="tb-cell list-left">外送</div>
					<div class="tb-cell list-right">
						<input type="checkbox" id="is_take" name="take" class="box-radio"  <if condition = "$takeout eq 1">checked</if> style="width: 15px;height: 15px;-webkit-appearance: checkbox;">
					</div>
				</div>
				<empty name="userAddress">
					<div class="form-box">
						<div class="form-list hide">
							<input type="text" name="send_address" class="edit_address" placeholder="请输入外送地址">
						</div>
					</div>
					<!--<input type="text" name="send_address" class="edit_address"  style="display: none;width: 100%;height: 30px;margin-bottom: 15px;padding: 0" placeholder="请输入外送地址">-->
				<else/>
					<div class="form-box">
						<div class="form-list hide">
							<input type="text" name="send_address" class="edit_address" value="{BEESCRM:$userAddress.address}">
						</div>
					</div>
					<!--<input type="text" name="send_address" class="edit_address" style="display: none;width: 100%;height: 30px;margin-bottom: 15px;padding: 0" value="{BEESCRM:$userAddress.address}">-->
				</empty>
			</div>
			</div>
	</if>
    <div class="order-lists lists">
        <div class="lists tb-mode">
	        <div class="tb-cell list-left">餐品列表</div>
        </div>
        <volist name="goodList" id="vo">
	    <div class="lists tb-mode foods">
            <a href="javascript:void(0);" class="tb-cell list-left">
                <div class="img-box"><img src="{BEESCRM:$vo['goods_logo']}"></div>
            </a>
            <a href="javascript:void(0);" class="tb-cell list-center">
                <p>{BEESCRM:$vo['goods_name']}</p>
                <p class="prize">{BEESCRM:$vo['goods_price']}元</p>
            </a>
            <div class="tb-cell list-right">
                <div class="tb-mode amount" style="text-align: center;border:0;">
	                {BEESCRM:$vo['goods_num']}<span class="wd-good" style="display: none;">x1</span>
                </div>
            </div>
        </div>
        </volist>
        <div class="lists tb-mode">
            <div class="tb-cell list-right" style="line-height: 1.5;">
				<!--<p id="sendPrice">餐盒费：0元</p>-->
				<!--<p>积分优惠：0元</p>-->
				<p>
					总价：<span class="num" id="orderPrice">{BEESCRM:$data.moneySum}元</span>
					<input type="hidden" value="{BEESCRM:$data.moneySum}" id="orderAmount">
				</p>
			</div>
        </div>

        <div class="lists bottom-none">
            <input placeholder="特殊需要请备注" id="memo" value="{BEESCRM:$irs_memo}" />
        </div>
    </div>
	<input type="hidden" class="restaurant_id" value="{BEESCRM:$redectory_id}">
	<input type="hidden" class="window_id" value="{BEESCRM:$window_id}">
	<input type="hidden" id="irs_id" value="{BEESCRM:$res_id}">
	<input type="hidden" id="takeout" value="{BEESCRM:$takeout}">
	<input type="hidden" id="amount" value="{BEESCRM:$amount}">
	<input type="hidden" id="freight" value="{BEESCRM:$freight}">
	<input type="hidden" id="pay_type" value="{BEESCRM:$pay_type}">
    <div class="btn-box">
        <a href="javascript:void(0)" class="btn green-btn pay-btn" data-order_id="{BEESCRM:$order_id}">
			<if condition="$pay_type eq 4">
				确认挂账
			</if>
			<if condition="$pay_type eq 3">
				立即付款
			</if>
			<if condition="$pay_type eq 1">
				立即付款
			</if>

		</a>
    </div>
	<div class="pop-box " id="Opacity">
		<div class="pop-hint">
			<div class="text-center pop-title font-16">请选择支付方式</div>
			<div class="Radio">
				<div class="box-radio">
					<div class="line-radio">
						<input type="radio" id="a1" value="1" name="a" class="radio"	 <if condition="$pay_type eq 1">checked</if> >
						<label for="a1">微信支付</label>
					</div>
					<if condition="$account_id eq 38 or $account_id eq 4 or $account_id eq 60">
						<div class="line-one" style="margin: 15px"></div>
						<div class="line-radio">
							<input type="radio" id="a3" value="3" name="a" class="radio" <if condition="$pay_type eq 3">checked</if>>
							<label for="a3">一卡通支付</label>
						</div>
					</if>
					<div class="line-one" style="margin: 15px"></div>
					<if condition="($onAccountRight eq 1) AND ($windowOnAccountRight eq 1)">
						<div class="line-radio">
							<input type="radio" id="a2" value="4" name="a"  <if condition="$pay_type eq 4">checked</if> class="radio">
							<label for="a2">挂账</label>
						</div>
					</if>

					<!--<div class="line-radio"><input type="radio" id="a3" value="" name="a" class="radio"><label-->
					<!--for="a3">一卡通支付</label></div>-->
				</div>
			</div>
		</div>
	</div>
</div>

<include file="../commonJS" />
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="/assets/schoolirs/js/order.js?version=1"></script>
<script src="/assets/schoolirs/js/countdown.js?version=1"></script>
<!--禁用微信分享-->
<script>
	function onBridgeReady(){
		WeixinJSBridge.call('hideOptionMenu','hideToolbar');
	}

	if (typeof WeixinJSBridge == "undefined"){
		if( document.addEventListener ){
			document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
		}else if (document.attachEvent){
			document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
			document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
		}
	}else{
		onBridgeReady();
	}
</script>
<!--微信自带的返回-->
<script>

	$(function(){
		pushHistory();
		window.addEventListener("popstate", function(e) {
			//alert("我监听到了浏览器的返回按钮事件啦");//根据自己的需求实现自己的功能
			pushHistory();
		}, false);
		function pushHistory() {
			var state = {
				title: "title",
				url: "#"
			};
			window.history.pushState(state, "title", "#");//禁用
		}
		//绑定一卡通之后再跳回来
		var _takeout= "{BEESCRM:$takeout}";
		if(_takeout == 1) {
			$('.edit_address').parents('.form-list').removeClass('hide');
		}

	});
</script>
<script>
    $('.classify').click(function(){
        $('.menu-lists').addClass('show-menu');
    })
    $('.close').click(function(){
        $('.menu-lists').removeClass('show-menu');
    })
    if({BEESCRM:$hasBalconyRight} ==0){
        $("#balcony_div").empty();
    }
</script>

<script>
	var closeTime = $("#close_time").val();
	var irsId = $("#irs_id").val();
	var orderId = $("#orderId").val();



	//增减外带份数
	$(".change-num-btn").on('click',function(){
		var s = $(this).data('status');
		var num = $("#wd-num").val();
		var sendPrice = $("#send_price").val();
		if(s == 'sub'){//-
			var sub_num = parseInt(num) - 1;
			if(sub_num >= 1){
				upWdOrder(sub_num,orderId,sendPrice);

			}
		}else if(s == 'plus'){//+
			var plus_num = 1 + parseInt(num);
			upWdOrder(plus_num,orderId,sendPrice);
		}

	});

	//修改外带订单
	function upWdOrder(num,orderId,sendPrice){
		var info = {};
		info.orderId = orderId;
		info.num = num;
		info.sendPrice = sendPrice;
		$.ajax({
			'url': "/schoolirs/Order/carryOrder?res_id="+irsId,
			'data': info,
			'dataType':'json',
			'type': 'POST',
			'async': false,
			success: function(data) {
				if(data.status == 'S'){
					$("#wd-num").val(data.num);
				}else{
					fm.alert(data.message);
				}
			}
		});
	}


	//是否为外带订单
	function upOrder(besides,sendPrice){
		var orderId = $("#orderId").val();
		var info = {};
		info.orderId = orderId;
		info.besides = besides;
		info.sendPrice = sendPrice;
		$.ajax({
			'url': "/schoolirs/Order/besidesOrder?res_id="+irsId,
			'data': info,
			'dataType':'json',
			'type': 'POST',
			'async': false,
			success: function(data) {
				if (data.status == 'S') {
					var orderAmount = $("#orderAmount").val();
					if(besides == 1){
						var orderPrice = parseFloat(orderAmount) + parseFloat(data.sendPrice);
						$("#sendPrice").html("餐盒费:"+data.sendPrice+"元");
						$("#orderPrice").html(orderPrice.toFixed(2)+'元');
					}else{
						$("#sendPrice").html("餐盒费:0元");
						$("#orderPrice").html(orderAmount+'元');
					}
				}else{
					fm.alert(data.message);
				}
			}
		});
	}

	//选择口味
	$("#flavor_inp").change(function(){
		//修改订单口味
		var info = {};
		info.orderId = orderId;
		info.flavor = $("#flavor_inp option:selected").val();
		$.ajax({
			'url': "/schoolirs/Order/flavorOrder?res_id="+irsId,
			'data': info,
			'dataType':'json',
			'type': 'POST',
			'async': false,
			success: function(data) {
				if (data.status == 'S') {}else{}
			}
		});
	})


    //选择支付方式
        $('#paytype').click(function () {
            $('#Opacity').show();
        })
		$('.pop-box').on('click',function () {
			$(this).hide();
        });
		$('.pop-title').click(function (e) {
            e.stopPropagation();
        })
        $('#Opacity').on('click','.line-radio',function () {

            var html=$(this).text() + '<span class="iconfont icon-you"></span>';
           $('.paymethod').html(html);
			if($('input:radio[name="a"]:checked').val()==1){
				$('.pay-btn').text('立即付款');
				$('#pay_type').val('1');
			}else if($('input:radio[name="a"]:checked').val()==3){
				$('.pay-btn').text('立即付款');
				$('#pay_type').val('3');
			}else if($('input:radio[name="a"]:checked').val()==4){
				$('.pay-btn').text('确定挂账');
				$('#pay_type').val('4');
			}
//			else {
//				$('#pay_type').val('1');
//				$('.pay-btn').text('立即付款');
//			}
			$('#Opacity').hide();
        });

	// 选桌
	$(document).on('click', '.abledbalcony', function () {
        var type = $('#pay_type').val();
        var windowId = $('.window_id').val();
        var info = {};
        info.window_id =windowId;
        info.order_id =orderId;
        $.ajax({
            'url': "/Schoolirs/Order/hasFreeBalcony?res_id="+irsId,
            'data': info,
            'dataType':'json',
            'type': 'POST',
            'async': false,
            success: function(data) {
                if (data.status == 'S') {

                    var url="/Schoolirs/Order/choseBalcony?window="+windowId+"&type="+type+"&res_id="+irsId+"&order_id="+orderId;

                    location.href = url;
                }else{
                    fm.alert(data.message);
                    return false;
                }
            }
        });
	});
</script>
<!-- 修改外带事件 -->
<script>
	var oBox= document.getElementById('is_take');
	oBox.onclick =function(){
		var besides=0;
		if(this.checked){
			$('.edit_address').parents('.form-list').removeClass('hide');
            besides = 1;
        } else{
			$('.edit_address').parents('.form-list').addClass('hide');
			besides = 0;
		}
		var info = {};
		info.order_id =orderId;
		info.besides = besides;
		$.ajax({
			'url': "/Schoolirs/Order/besidesOrder?res_id="+irsId,
			'data': info,
			'dataType':'json',
			'type': 'POST',
			'async': false,
			success: function(data) {
				if (data.status == 'S') {

				}else{

				}
			},
			errors: function () {

			}
		});
	}
</script>
<!-- 修改默认地址事件 -->
<script>
	var primaryAddress = '';
	$('.edit_address').focus(function(){
		primaryAddress = $(this).val();
	});
	$('.edit_address').blur(function(){
       var nowAddress = $(this).val();
	   if (nowAddress!=''){
		   if (primaryAddress != nowAddress){
			  // 新增或者修改默认送货地址
			   var type = 1;
			   if (primaryAddress==''){
				   type = 1;//新增
			   }else {
				   type=2;//修改
			   }
			   var info = {};
			   info.order_id =orderId;
			   info.type = type;
			   info.address = nowAddress;
			   $.ajax({
				   'url': "/Schoolirs/Order/doUserSendAddress?res_id="+irsId,
				   'data': info,
				   'dataType':'json',
				   'type': 'POST',
				   'async': false,
				   success: function(data) {
					   if (data.status == 'S') {

					   }else{
						   //失败,不做修改,将原来的地址放到地址输入框
						   $('.edit_address').val(primaryAddress);
					   }
				   },
				   errors: function () {
					   $('.edit_address').val(primaryAddress);
				   }
			   });
		   }
	   }
	});
</script>
</body>
</html>
